package com.y.architecture.base_tab;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.y.architecture.R;
import com.y.architecture.base.NeedInitViewHelper;
import com.y.architecture.util.AFConstant;


/**
 * Created by youjingjing on 2017/11/29.
 */

public class BaseTabPagerHelper<T extends IBaseTabPageContact.IPageTitle> extends NeedInitViewHelper<IBaseTabPageContact.IBaseTabPageView<T>> implements IBaseTabPageContact.IBaseTabPagerPresenter {

    private TabLayout mTabLayout;
    private ViewPager mPager;

    public BaseTabPagerHelper(IBaseTabPageContact.IBaseTabPageView<T> mBaseView) {
        super(mBaseView);
    }

    public BaseTabPagerHelper(IBaseTabPageContact.IBaseTabPageView<T> mBaseView, View mRoot) {
        super(mBaseView, mRoot);
    }

    @Override
    public TabLayout setTabLayout() {
        mTabLayout = getView(mBaseView.getTabId());
        return  mTabLayout;
    }

    @Override
    public ViewPager setPager() {
        mPager = getView(mBaseView.getPagerId());
        return mPager;
    }

    @Override
    public int getDefaultTabId() {
        return R.id.pre_tab_layout;
    }

    @Override
    public int getDefaultPageId() {
        return R.id.pre_pager;
    }

    @Override
    public void createPager() {
        mPager.setAdapter(new PagerFragmentAdapter<T>(mBaseView.getAFFragmentManager(), mBaseView.getItems(), mBaseView));

        mPager.setOffscreenPageLimit(AFConstant.PAGE_CACHE_SIZE);

//        mBaseView.setTabSpaceEqual();

        mTabLayout.setupWithViewPager(mPager);
//        mTabLayout.setOnTabSelectedListener(mBaseView);
    }

}
